package com.rongke.web.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.rongke.commons.JsonResp;
import com.rongke.mapper.TransactionDataMapper;
import com.rongke.model.EachPicture;
import com.rongke.model.Information;
import com.rongke.model.TransactionData;
import com.rongke.service.TransactionDataService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;

/**
 * @TransactionDataController
 * @期权交易数据Controller
 * @version : Ver 1.0
 */
@RestController
@RequestMapping(value="/api/transactionData")
@Transactional
@CrossOrigin
public class TransactionDataController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private TransactionDataService transactionDataService;

    /**
     * @添加期权交易数据
     * @param transactionData
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/add", method = RequestMethod.POST)
    public JsonResp addTransactionData(@RequestBody TransactionData transactionData){
        log.debug("添加期权交易数据");
        transactionDataService.insert(transactionData);
        return JsonResp.ok(transactionData);
    }

    /**
     * @修改期权交易数据
     * @param transactionData
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/update", method = RequestMethod.POST)
    public JsonResp updateTransactionData(@RequestBody TransactionData transactionData){
        log.debug("修改期权交易数据");
        transactionDataService.updateById(transactionData);
        return JsonResp.ok(transactionData);
    }
    /**
     * @根据id查找期权交易数据
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectOne", method = RequestMethod.GET)
    public JsonResp selectTransactionData(Long id){
        log.debug("查找期权交易数据");
        TransactionData transactionData = transactionDataService.selectById(id);
        return JsonResp.ok(transactionData);
    }

    /**
     * @所有期权交易数据
     * @param
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectTransactionMsg", method = RequestMethod.GET)
    public JsonResp selectTransactionMsg(){
        EntityWrapper<TransactionData> ew=new EntityWrapper<>();
        ew.orderBy("gmt_datetime",false);
        List<TransactionData> list=transactionDataService.selectList(ew);
        return JsonResp.ok(list);
    }



}
